package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.form.menu.AddMenuForm;
import com.example.teachingSystem.pojo.form.menu.ChangeMenuForm;
import com.example.teachingSystem.pojo.form.menu.MenuPageQuery;
import com.example.teachingSystem.pojo.vo.MenuInfoVo;
import com.example.teachingSystem.pojo.vo.OptionVo;
import com.example.teachingSystem.pojo.vo.RouteVo;
import com.example.teachingSystem.service.SysMenuService;
import com.example.teachingSystem.service.SysRoleMenuService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Tag(name = "4.菜单模块")
public class MenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    @GetMapping("/one/{id}")
    @Operation(summary = "根据Id获取菜单详情", security = {@SecurityRequirement(name = "Authorization")})
    public Result<MenuInfoVo> getMenuById(@PathVariable Long id) {
        return sysMenuService.getMenuById(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取菜单分页", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<MenuInfoVo> getMenuPage(MenuPageQuery menuPageQuery) {
        return sysMenuService.getMenuPage(menuPageQuery);
    }

    @PostMapping("/one")
    @Operation(summary = "添加菜单", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addMenu(@RequestBody  AddMenuForm addMenuForm) {
        return sysMenuService.addMenu(addMenuForm);
    }

    @PutMapping("/one")
    @Operation(summary = "修改菜单", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateMenu(@RequestBody ChangeMenuForm changeMenuForm) {
        return sysMenuService.updateMenu(changeMenuForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除菜单", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteMenu(@PathVariable Long id) {
        return sysMenuService.deleteMenu(id);
    }

    @GetMapping("/option")
    @Operation(summary = "获取菜单选项", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<MenuInfoVo>> getMenuOptions(){
        return sysMenuService.getMenuOptions();
    }

    @GetMapping("/routes/{roleId}")
    @Operation(summary = "获取路由列表", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<RouteVo>> getRoutes(@PathVariable Long roleId){
        return sysMenuService.getRoutes(roleId);
    }

    @GetMapping("/option/{roleId}")
    @Operation(summary = "获取角色下的菜单id列表", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<Long>> getMenuOptionById(@PathVariable Long roleId){
        return sysRoleMenuService.getMenuOptionById(roleId);
    }
}
